#include "TCamera.h"
//using namespace DirectX;
void TRenderCore::TCamera::LookAt(const XMFLOAT3 &wolrdUp, const XMFLOAT3& target)
{
	DirectX::XMVECTOR P = DirectX::XMLoadFloat3(&mPosition);
	DirectX::XMVECTOR T = DirectX::XMLoadFloat3(&target);
	DirectX::XMVECTOR U = DirectX::XMLoadFloat3(&wolrdUp);
	
	DirectX::XMVECTOR _lookatDir = T - P;
	XMVECTOR _right = XMVector3Cross(U, _lookatDir);

	auto up = XMVector3Cross(_lookatDir, _right);

	XMStoreFloat3(&mRight, _right);
	XMStoreFloat3(&mUp, up);
	XMStoreFloat3(&mFront,_lookatDir);
}


void TRenderCore::TCamera::UpdateViewMatrix()
{
	mViewMatrix(0, 1) = mRight.x;
	mViewMatrix(1, 1) = mRight.y;
	mViewMatrix(2, 1) = mRight.x;

	mViewMatrix(0, 2) = mUp.x;
	mViewMatrix(1, 2) = mUp.y;
	mViewMatrix(2, 2) = mUp.x;

	mViewMatrix(0, 3) = mRight.x;
	mViewMatrix(1, 3) = mRight.y;
	mViewMatrix(2, 3) = mRight.z;

	
}
